<?php
$eventpropertyStr = Yii::t('BWeSport', 'Event Property');
$detailcontentStr = Yii::t('BWeSport', 'Detail Content');
$eventtypeStr = Yii::t('BWeSport', 'Event Type');
$eventnameStr = Yii::t('BWeSport', 'Event Name');
$eventimageStr = Yii::t('BWeSport', 'Event Image');
$eventstarttimeStr = Yii::t('BWeSport', 'Event Start Time');
$eventendtimeStr = Yii::t('BWeSport', 'Event End Time');
$eventprofileStr = Yii::t('BWeSport', 'Event Profile');
$starttimeStr = Yii::t('BWeSport', 'Start Time');
$endtimeStr = Yii::t('BWeSport', 'End Time');
?>
<?php
$model = new BDynamicFormModel();
$modelClass = get_class($model);
$screen = Blyn::app()->getUIManager()->getCurrentScreen();
$url = $control->getAjaxLinkUrl('saveEvent', NULL, array(
    'eventId' => $eventId,
    'postModel' => $modelClass));
$updateId = $control->getAjaxContainerId();
?>
<?php
$eventTypeField = 'eventType_eventTypeId';
$eventNameField = 'event_name';
$eventDescriptionField = 'event_description';
$model->addField($eventNameField);
$model->addField($eventDescriptionField);
$model->addField($eventTypeField);

if ($eventId > 0) {
    $event = new BWEvent($eventId);
    $eventType = $event->getType();
    if ($eventType)
        $model->$eventTypeField = $eventType->getId();
    $model->$eventNameField = $event->name;
    $model->$eventDescriptionField = $event->description;
}
?>
<?php
$app = Blyn::app()->getActiveApp();
$typeList = $app->getEventTypeList('FullName');
$list = array('0' => '请选择');
$typeList = $list + $typeList;
?>
<?php
$form = $this->beginWidget('CActiveForm', array(
    "id" => "addEventForm",
    //'enableAjaxValidation' => FALSE,
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
        ));
?>
<script type="text/javascript">
// this script for collecting the form data and pass to the controller action and doing the on success validations
    function sendIt() {

//        var formData = new FormData($("#message-form")[0]);
        var formElement = document.getElementById("addEventForm");
        var formData = new FormData(formElement);

        $.ajax({
            url: '<?php echo $url; ?>',
            type: 'POST',
            data: formData,
            //datatype: 'html',
            // async: false,
            beforeSend: function() {
                //alert('url:');
                //alert('data:');
                $("#ajax-loaderdiv").show();
                //alert('1');
            },
            success: function(data) {
                // on success do some validation or refresh the content div to display the uploaded images 
                //alert(data);
                jQuery("#<?php echo $updateId; ?>").html(data);
            },
            complete: function() {
                //alert("3");
                $("#ajax-loaderdiv").hide();
            },
            error: function(jqXHR, textStatus, errorThrown) {
                //alert(textStatus);
                //alert(textStatus+';'+errorThrown);
                alert("There may a error on uploading. Try again later");
            },
            cache: false,
            contentType: false,
            processData: false
        });

        return false;
    }
</script>
<legend><h4><?php echo $control->getAjaxLink(array('name' => '活动列表', 'id' => 'showEventList')); ?>\活动内容
    </h4></legend>
<div class="tabbable tabs-right" style="margin-top: 15px;"> <!-- Only required for left/right tabs -->
    <div class="tab-content">
        <div class="tab-pane active" id="tab1" style="min-height: 270px">                
            <table class="table table-striped">
                <colgroup>
                    <col class="span1">
                    <col class="span7">
                </colgroup>
                <thead>
                    <tr>
                        <th><?php echo $eventpropertyStr; ?></th>
                        <th><?php echo $detailcontentStr; ?></th>
                    </tr>
                </thead>
                <tbody>
                <tr>
                    <td>
                        <code><?php echo $eventtypeStr; ?></code>
                    </td>
                    <td>
                        <?php
                        echo $form->dropDownList($model, $eventTypeField, $typeList, array('class' => 'span7'));
                        ?>
                        <!--                    &nbsp;&nbsp;&nbsp;&nbsp;<a id="CreateNewType_clink" role="button" data-toggle="modal" class="btn disabled" style="font-size: 12px;margin-top: -12px;">创建新类型</a>-->
                    </td>
               </tr>
                    <tr><td> <code><?php echo $eventnameStr; ?></code> </td>
                        <td>
                            <?php
                            echo $form->textField($model, $eventNameField, array('placeholder' => $eventnameStr . '...', 'required' => true));
                            ?>
                        </td>
                    </tr>               
                    <tr>
                        <td> <code><?php echo $eventprofileStr; ?></code>  </td>                    
                        <td>
                            <?php
                            echo $form->textArea($model, $eventDescriptionField, array('placeholder' => $eventprofileStr . '...'));
                            ?>
                    </tr>
                </tbody>
            </table> 
        </div>     
    </div>
</div>
<?php
$this->endWidget();
//echo CHtml::endForm();
?>
<button class="btn" onclick="javascript:sendIt()">保存</button>